import { Router } from 'express';
import { QuestionController } from '../controllers/questionController';
import { auth } from '../middleware/auth';
import { roleAuth } from '../middleware/roleAuth';
import { asyncHandler } from '../middleware/asyncHandler';
import { validateQuestion } from '../middleware/validators/questionValidator';
import { TypedRequest } from '../middleware/routeHandler';

const router = Router();

// === Apply Authentication ===
router.use(auth);

// === Question Routes ===

// Get all questions (with filtering and pagination)
router.get('/', 
  roleAuth(['teacher', 'admin', 'student']),
  asyncHandler(QuestionController.getQuestions)
);

// Get single question by ID
router.get('/:id',
  roleAuth(['teacher', 'admin', 'student']),
  asyncHandler(QuestionController.getQuestion)
);

// Create new question
router.post('/',
  roleAuth(['teacher', 'admin']),
  validateQuestion,
  asyncHandler(QuestionController.createQuestion)
);

// Update existing question
router.put('/:id',
  roleAuth(['teacher', 'admin']),
  validateQuestion,
  asyncHandler(QuestionController.updateQuestion)
);

// Delete question
router.delete('/:id',
  roleAuth(['teacher', 'admin']),
  asyncHandler(QuestionController.deleteQuestion)
);

// Batch delete questions
router.post('/batch-delete',
  roleAuth(['admin']),
  QuestionController.batchDelete
);

// Export questions
router.get('/export',
  roleAuth(['teacher', 'admin']),
  QuestionController.exportQuestions
);

export default router;
